     // 三级菜单
     $(function(){
        $(".menu").find("li").hover(function(){
            $(this).children("ul").show();
        },function(){
            $(this).children("ul").hide();
        })
    })
 
 
 // 放大镜 
 const imgs = [{
    s:"./images/teas1.jpg",
    m:"./images/tea1.jpg",
    l:"./images/teal1.jpg",
},{
    s:"./images/teas2.jpg",
    m:"./images/tea2.jpg",
    l:"./images/teal2.jpg",
},{
    s:"./images/teas3.jpg",
    m:"./images/tea3.jpg",
    l:"./images/teal3.jpg",
},{
    s:"./images/teas4.jpg",
    m:"./images/tea4.jpg",
    l:"./images/teal4.jpg",
},{
    s:"./images/teas5.jpg",
    m:"./images/tea5.jpg",
    l:"./images/teal5.jpg",
}];


// 点击小图切换中图和大图
function Tab(){
this.li = document.querySelectorAll(".content-half li");
this.sImg = document.querySelector(".small_box img");
this.bImg = document.querySelector(".big_box img");
this.data = imgs;
this.index = 0;
this.addEvent();
}
Tab.prototype.addEvent = function(){
const that = this;
for(let i=0;i<this.li.length;i++){
    this.li[i].xuhao = i;
    this.li[i].onclick = function(){
        that.hide();
        that.getIndex(this);
    }
}
}
Tab.prototype.hide = function(){
this.li[this.index].className = "";
}
Tab.prototype.getIndex = function(now){
this.index = now.xuhao;
this.show();
}
Tab.prototype.show = function(){
this.li[this.index].className = "active";   
this.sImg.src = this.data[this.index].m;
this.bImg.src = this.data[this.index].l;
}
new Tab();





 class Magnifier{
    constructor(){
        this.sBox = document.querySelector(".small_box");
        this.sSpan = document.querySelector(".small_box span");
        this.bBox = document.querySelector(".big_box");
        this.bImg = document.querySelector(".big_box img");
        this.addEvent();
    }
    move(ops){
        let l = ops.x - this.sSpan.offsetWidth/2;
        let t = ops.y - this.sSpan.offsetHeight/2;
        if(l < 0) l = 0;
        if(t < 0) t = 0;
        if(l > this.sBox.offsetWidth - this.sSpan.offsetWidth){
            l = this.sBox.offsetWidth - this.sSpan.offsetWidth;
        }
        if(t > this.sBox.offsetHeight - this.sSpan.offsetHeight){
            t = this.sBox.offsetHeight - this.sSpan.offsetHeight;
        }
        this.sSpan.style.left = l + "px";
        this.sSpan.style.top = t + "px";
        const x = l / (this.sBox.offsetWidth - this.sSpan.offsetWidth);
        const y = t / (this.sBox.offsetHeight - this.sSpan.offsetHeight);
        this.bImg.style.left = -x * (this.bImg.offsetWidth - this.bBox.offsetWidth) + "px";
        this.bImg.style.top = -y * (this.bImg.offsetHeight - this.bBox.offsetHeight) + "px";
    }
    init(){
        this.sSpan.style.width = this.bBox.offsetWidth / this.bImg.offsetWidth * this.sBox.offsetWidth + "px";
        this.sSpan.style.height = this.bBox.offsetHeight / this.bImg.offsetHeight * this.sBox.offsetHeight + "px";
    }
    addEvent(){
        const that = this;
        this.sBox.onmouseenter = function(){
            that.show();
        }
        this.sBox.onmouseleave = function(){
            that.hide();
        }
        this.sBox.onmousemove = function(eve){
            const e = eve || window.event;
            const pos = {
                x:e.offsetX,
                y:e.offsetY
            };
            that.move(pos);
        }
    }
    show(){
        this.sSpan.style.display = "block";
        this.bBox.style.display = "block";
        this.init();
    }
    hide(){
        this.sSpan.style.display = "none";
        this.bBox.style.display = "none";
    }
}
new Magnifier();